package com.baosight.ice.observer;

import com.baosight.ice.repository.ApplicationRepository;
import com.zeroc.Ice.Current;
import com.zeroc.IceGrid.ApplicationInfo;
import com.zeroc.IceGrid.ApplicationObserver;
import com.zeroc.IceGrid.ApplicationUpdateInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class ApplicationObserverI implements ApplicationObserver {
    public static Logger logger = LoggerFactory.getLogger(ApplicationObserverI.class);
    @Override
    public void applicationInit(int i, List<ApplicationInfo> list, Current current) {
        System.out.println("applicationInit "+i+" "+list.toString());
        if (list.size()==0){
            System.out.println("applicationInit (no application);" + "serial is " + i);
        }else{
            String names = "";
            for(ApplicationInfo p : list)
            {
                names += " " + p.descriptor.name;
            }
            System.out.println("applicationInit for application "+names+"; serial is "+i);
        }

        new ApplicationRepository().setApplicationList(list);
    }

    @Override
    public void applicationAdded(int i, ApplicationInfo applicationInfo, Current current) {
        System.out.println("applicationAdded "+i+" "+applicationInfo.toString());
    }

    @Override
    public void applicationRemoved(int i, String s, Current current) {
        System.out.println("applicationRemoved "+i+" "+s.toString());
    }

    @Override
    public void applicationUpdated(int i, ApplicationUpdateInfo applicationUpdateInfo, Current current) {
        System.out.println("applicationUpdated "+i+" "+applicationUpdateInfo.toString());
    }
}
